package com.object.module.cbb.frontEnd;

import com.object.configuration.utils.PageUtils;
import com.object.configuration.utils.Q;
import com.object.module.cbb.entity.CddShopEntity;
import com.object.module.cbb.service.CddShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;


/**
 * 商品
 *
 * @author 小🌤
 * @email 1578442339@qq.com
 * @date 2021-12-29 21:06:27
 */
@RestController
@RequestMapping("/frontend/shop")
public class FrontEndCddShopController {
    @Autowired
    private CddShopService cddShopService;

    //热门推荐
    @GetMapping("/popularRecommendation")
    public Q popularRecommendation() {
        return cddShopService.popularRecommendation();
    }

    // 最新上架
    @GetMapping("/newArrival")
    public Q newArrival() {
        return cddShopService.newArrival();
    }

    // 人气商品
    @GetMapping("/popularProduct")
    public Q popularProduct() {
        return cddShopService.popularProduct();
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    public Q list(@RequestParam Map<String, Object> params) {
        PageUtils page = cddShopService.queryPage(params);
        return Q.ok().put("data", page);
    }

    /**
     * 首页推荐10个商品
     */
    @GetMapping("/sye")
    public Q sye() {
        Map<String, Object> map = new HashMap<>();
        PageUtils page = cddShopService.queryPage(map);
        return Q.ok().put("data", page.getList());
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{spId}")
    public Q info(@PathVariable("spId") Integer spId) {
        CddShopEntity cddShop = cddShopService.getByIdInfo(spId);
        return Q.ok().put("cddShop", cddShop);
    }

    /**
     * 根据id查询信息
     */
    @RequestMapping("/infoId/{spId}")
    public CddShopEntity infoId(@PathVariable("spId") Long spId) {
        return cddShopService.getById(spId);
    }

}
